//
//  PPAssetsPictureViewController.m
//  pickpic
//
//  Created by Jinxiao on 10/26/16.
//  Copyright © 2016 MicroDream. All rights reserved.
//

#import "PPAssetsPictureViewController.h"

#import "PPAssetsPictureViewStatusBar.h"

@interface PPAssetsPictureViewController () <PPAssetsPictureViewStatusBarDelegate>
@property (readwrite, nonatomic, strong) PPAssetsPictureViewStatusBar *statusBar;
@end

@implementation PPAssetsPictureViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    _statusBar = [[PPAssetsPictureViewStatusBar alloc] init];
    _statusBar.backgroundColor = [UIColor colorWithRGBHex:0x1a1a1a];
    _statusBar.delegate = self;
    [self.view addSubview:_statusBar];

    [self layoutSelection];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

    _statusBar.frame = CGRectMake(0, self.view.height - 49, self.view.width, 49);
}

- (void)layoutSelection {
    BOOL selected = [_delegate pictureViewController:self selectionStatusForItemAtIndex:self.index];

    _statusBar.selected = selected;

    NSInteger count = [_delegate numberOfSelectionsForPictureViewController:self];

    _statusBar.count = count;
}

- (void)didEndScrolling {
    [super didEndScrolling];

    [self layoutSelection];
}

- (NSArray <UIView *> *)extraViewsToHidden {
    return @[_statusBar];
}

#pragma mark - PPAssetsPictureViewStatusBarDelegate

- (void)pictureStatusBarDidPressSelectButton:(PPAssetsPictureViewStatusBar *)pictureStatusBar {
    [_delegate pictureViewController:self didChangeSelectionOfItemAtIndex:self.index];

    [self layoutSelection];
}

- (void)pictureStatusBarDidPressDoneButton:(PPAssetsPictureViewStatusBar *)pictureStatusBar {
    [_delegate pictureViewControllerDidConfirmed:self];
}

@end
